package controller

import (
	"fmt"
	errorStatus "gin_note/error_status"
	"gin_note/model"
	"net/http"

	"github.com/gin-gonic/gin"
)

func User_controller_login(ctx *gin.Context) {
	fmt.Println("user login")
	user := ctx.PostForm("username")
	password := ctx.PostForm("password")

	fmt.Println("user:" + user + " password:" + password)

	res := model.User_login(user, password)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    errorStatus.StatusText(res),
		"message": "user finish!",
	})
}

func User_controller_password(ctx *gin.Context) {
	fmt.Println("user password")
	user := ctx.PostForm("username")
	oldpassword := ctx.PostForm("oldpassword")
	newpassword := ctx.PostForm("newpassword")

	res := model.User_password(user, oldpassword, newpassword)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    errorStatus.StatusText(res),
		"message": "user finish!",
	})
}

func User_controller_zhuce(ctx *gin.Context) {
	fmt.Println("user zhuce")
	user := ctx.PostForm("username")
	password := ctx.PostForm("password")

	res := model.User_zhuce(user, password)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    errorStatus.StatusText(res),
		"message": "user finish!",
	})
}

func Logout(ctx *gin.Context) {
	fmt.Println("user logout")
}
